import pymysql

"""
checkUser(userName,Password)   return True or False
Register(suerName,Password)    return True or False
addTaskaddTask(listID,taskID,taskStartTime,taskEndTime,taskRemindTime,Level,Order,Cycle,Summary,Detail,Comment) return True or False
addList(userID,listID,Order,Color,Type,listName) return True or False
"""


#connect to Mysql
db = pymysql.connect(host='localhost',user='root',password='root',db='GUGUADB',port=3306)
cursor = db.cursor()


def check(userName,Password):
	sql = "select userPassword from User where userName= \'"+ userName+"\';"
	cursor.execute(sql)
	passW=cursor.fetchone()
	print(passW[0])
	print(password)
	print(password == passW[0])
	if passW[0] == password :
		return True
	else : 
		return False

def Register(userName,userPassword,userID,Email,Telephone):
		
	sqlInsert = "insert into User (userName,userPassword,userID,Email,Telephone) values("+"\'"+userName+"\'"+","+"\'"+userPassword+"\'"+","+"\'"+userID+"\'"+","+"\'"+Email+"\'"+","+"\'"+Telephone+"\'"+");"
	print(sqlInsert)
	try:
		cursor.execute(sqlInsert)
	except Exception :
		return False
		
	else :
		return True




def addTaskaddTask(listID,taskID,taskStartTime,taskEndTime,taskRemindTime,Level,Order,Cycle,Summary,Detail,Comment):
	sqlInsert = "insert into Task (listID,taskID,taskStartTime,taskEndTime,taskRemindTime,Level,Order,Cycle,Summary,Detail,Comment) values("+"\'"+listID+"\'"+","+"\'"+taskID+"\'"+","+"\'"+taskStartTime+"\'"+",\'"+taskEndTime+"\',"+"\'"+taskRemindTime+"\'"+","+"\'"+Level+"\'"+","+"\'"+Order+"\'"+","+"\'"+Cycle+"\'"+","+"\'"+Summary+"\'"+","+"\'"+Detail+"\'"+","+"\'"+Comment+"\'"+");"
	try:
		cursor.execute(sqlInsert)
	except Exception:
		return False

	else :
		return True



def addList(userID,listID,Order,Color,Type,listName):
	sqlInsert = "insert into List (userID,listID,Order,Color,Type,listName) values(\'"+userID+"\',\'"+listID+"\',\'"+Order+"\',\'"+Color+"\',\'"+Type+"\',\'"+listName+"\')"
	#try:
	print(sqlInsert)
	cursor.execute(sqlInsert)
	#except Exception:
		#return False

	#else :
		#return True

# Register('userName','userPassword','1333','Email','Telephone')
addList("1333","1","10","red","note","notename")